package at.theengine.android.gs4android;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import at.theengine.android.botstorage.*;

public class Settings extends Activity {
	
	public static final String PREFS_NAME = "GS4ANDROID_SETTINGS";

	private EditText txtGsKey;
	private EditText txtGsSecret;
	private EditText txtDownloadDir;
	
	private Button btnsave;
	private Button btnCancel;
	
	private SharedPreferences settings;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.settings);
        
        txtGsKey = (EditText) findViewById(R.id.txtGsKey);
        txtGsSecret = (EditText) findViewById(R.id.txtGsSecret);
        txtDownloadDir = (EditText) findViewById(R.id.txtDownloadDir);
        
        btnsave = (Button) findViewById(R.id.btnSaveSettings);
        btnsave.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
            	saveSettings();
            }
        });
        
        btnCancel = (Button) findViewById(R.id.btnCancelSettings);
        btnCancel.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
            	exit();
            }
        });
        
        loadSettings();
    }
    
    private void exit(){
    	this.finish();
    }
    
    private void loadSettings(){
        settings = getSharedPreferences(PREFS_NAME, 0);
        txtGsKey.setText(settings.getString("gsKey", "GOOGRLXYH6VPHLMGJVFX"));
        txtGsSecret.setText(settings.getString("gsSecret", "5D3zLgg6vfA1tfM0NpAcDOv7ia1ic4K50dykXBVP"));
        txtDownloadDir.setText(settings.getString("gsDownloadDir", ""));
    }
    
    private void saveSettings(){
    	settings = getSharedPreferences(PREFS_NAME, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString("gsKey", txtGsKey.getText().toString());
        editor.putString("gsSecret", txtGsSecret.getText().toString());
        editor.putString("gsDownloadDir", txtDownloadDir.getText().toString());

        editor.commit();
        exit();
    }
}